<script type="text/javascript" src="/public/library/hvn/captcha.redraw.js"></script>
<div class="white_bg" >
<div class="box white_bg">
	<?if (isset($this->viewParams['paginator'])) :?>
	<? 
		$items = $this->viewParams['paginator']->getCurrentItems();
		$sess = new Zend_Session_Namespace(CLU_NS);
		if (!$sess->userId)
			$sess->userId = 0;	
		$avatar = APP_PATH."/public/ufiles/%d/images/%s/avatar/avatar.jpg";
		$temp = sprintf($avatar, $sess->userId , "small");
	?>
	<a name="comment_start"></a>
		<?//for($i = 0;$i<min(15,count($items));$i++){ ?>
		<?foreach($items as $item):?>
			<?$temp = sprintf($avatar, $item['poster_id'] , "small");?>
			
			<? if($this->viewParams['region'] != 4) :?>
				<div class="blog_blast">
			<?else :?>
				<div class="blog_blast2">
			<?endif?>
				<div class="box_comment_<?=$item['id']?>">
					<div class="blog_blast_left">
						<?
							if ($item['poster_id'] > 0)
								$post_link = $this->hvnUrl(array('action' => 'view'), 'account'). "?id=" . $item['poster_id'];
							else 
								$post_link = "#";
						?>
					   <a href="<?=$post_link?>">
				    	<?if(file_exists($temp)):?>
							<img src="<?=$temp;?>" align="absmiddle">
						<?else:?>
							<img src="<?=sprintf($avatar, 0, "small");?>" align="absmiddle">
						<?endif?>
						</a>
					</div>
					<? if($this->viewParams['region'] != 4) :?>
				    <div class="blog_blast_right"> 
				    <?else :?>
				     <div class="blog_blast_right2"> 
				    <?endif?> 
			    	<a name="<?=$item['id']?>"></a>
					<div class="blog_blast_title">
						<a href="#<?=$item['id']?>"> <?=$item['title']?> </a>, <?=t(136) ?>
						<a href="<?=$post_link?>"> <?=$item['poster_name']?> </a>
			         		<?=t(3007)?> <?=date("G:i:s   j/n/Y", $item['created']) ?>
			         	<?if (
			         		($sess->userId == $item['poster_id'] && strpos($sess->userPermissions, 'delete own comment') )||  //commenter
			         		strpos($sess->userPermissions, 'delete comment') || //comment admin
			         		$sess->userId == $this->viewParams['content_poster_id'] || //content owner TODO
			         		strpos($sess->userPermissions, 'administer ' . $this->viewParams['content_type']) //admin content
			                        ):
			             ?>
			         		<a href="javascript:void()" name="delete-comment-<?=$item['id']?>-<?=$item['poster_id']?>" ><img title="<?=t(31)?>" align="right" src="public/themes/hard/images/blog_delete.jpg"/></a>
			         	<?endif?>
					</div> 
					
					<? if($this->viewParams['region'] != 4) :?>
				        <div class="blog_blast_top">
							<div class="blog_blast_top_content">
									<?=$item['comment_text']?>
							</div>
						</div>
						<div class="blog_blast_bottom"></div>
						
					<?else :?>
						<div class="blog_blast_top2">
						
						<div class="clear"></div>
						<div class="blog_blast_top_content2">
								<?=$item['comment_text']?>
						</div>
						</div>
						<div class="blog_blast_bottom2"></div>
					<?endif?>
	
					</div>
					</div>
				</div>
			<?endforeach?>
		<?//}?>	
  	<?else:?>
  		<div></div>
  	<?endif?>
</div>

<?if(!empty($sess->userId)):?>
<!--  new comment box -->
<br/><br/>
<a href="new-comment"></a>
<div class="box white_bg">
	<form id="new-comment-box" accept-charset="UTF-8" action="/<?=$sess->viewLang?>/comment/ajax/new-comment" method="post" >
		<??>
		<table border="0" cellpadding="0" cellspacing="0" width="">
			<tbody>
			<tr>
		    	<td colspan="5" class="blog_binhluan_title" align="left"><img src="public/themes/hard/images/blog_comment.jpg" align="absmiddle"> &nbsp;&nbsp;&nbsp;<?=t(602)?></td>
		  	</tr>
		    <? if (!$sess->userId) :?>
			<tr>
				<td align="right" height="31" width="64"><?=t(810)?> :</td>
				<td align="left" width="254">&nbsp;&nbsp;<?=$this->viewParams['form']->poster_name?></td>
			</tr>
		  
		  	<tr>
		  		<td align="right"  height="31" width="136"> <?=t(470)?> :</td>
				<td width="264">&nbsp;&nbsp;<?=$this->viewParams['form']->guest_email?></td>
			</tr>
		    <?endif ?>

		  
		  	<tr>
		  		<td align="right"  height="31" width="136"> <?=t(13)?> :</td>
				<td width="264">&nbsp;&nbsp;<?=$this->viewParams['form']->title?></td>
			</tr>

		  
		  	<tr >
		    	<td width="64"></td>
		    	<td colspan="3">&nbsp;
			   		<?=$this->viewParams['form']->comment_text?>
				</td>
		  	</tr>
		  	
		    
<!--		    <tr>-->
<!--		  		<td align="right" width="136"> <?=t(39)?> :</td>-->
<!--				<td width="264">&nbsp;&nbsp;&nbsp;-->
<!--				<?=$this->viewParams['form']->captcha_newcomment?> -->
<!--		    		<a href="javascript:void()" class="redraw"><?=t(22) ?> </a>-->
<!--				</td>-->
<!--			</tr>-->
		    
		    
		    <tr>
		        <td align="right" height="40" width="136"></td>
		        <td align="left">&nbsp;&nbsp;<?=$this->viewParams['form']->submit?>
		    </tr>
		    
			</tbody>
		</table>
		<input type="hidden" name="poster_id" value="<?=$sess->userId?>" />
		<input type="hidden" name="content_poster_id" value="<?=$this->viewParams['content_poster_id']?>" />
		<input type="hidden" name="content_id" value="<?=$this->viewParams['content_id']?>" />
		<input type="hidden" name="content_type" value="<?=$this->viewParams['content_type']?>" />
		<input type="hidden" name="region" value="<?=$this->viewParams['region']?>" />
		<input type="hidden" name="type" value="<?=$this->viewParams['content_type']?>" />
		<br/><br/>
	</form>
</div>

<?endif?>
		  
</div> <!-- wrap both list and new comment -->		  
<script type="text/javascript">
$(function(){
	//$("dt").hide();
	$("#submit_comment").click(function(){
	    var oEditor = FCKeditorAPI.GetInstance('comment_text') ;
	    $("#comment_text").val(oEditor.GetData()); 
		$("#new-comment-box").submit();
		return false;
	});

	$("#new-comment-box").ajaxForm({
			dataType:  'json',
			success: function(json) {
				if(json.success){
					
					//set default values 
					alert("Thank you");
					//window.location.reload();					
					return false;
				}
				else{
					//alert when error found
					alert(json.errorMessage);
					$("a.redraw").trigger("click");
					return false;
				}
			}
		});
	$("a[name^=delete-comment]").click(function(){
		var del = confirm("Do you want to delete this comment?");
		deleteId = this.name.split('-')[2];
		posterId = this.name.split('-')[3];
		//alert(deleteId); del =0;
		if (del){	
			$.getJSON("/<?=$sess->viewLang?>/comment/ajax/delete-comment", {
				'id': deleteId,
				'poster_id': posterId,
				'content_id' : '<?=$this->viewParams['content_id']?>',
				'content_poster_id' : '<?=$this->viewParams['content_poster_id']?>',
				'content_type' : '<?=$this->viewParams['content_type']?>',
				},
            function(json) {
                if(json.success){	
                	$(".box_comment_" + deleteId).css('background-color','red').fadeOut(2000);
 			    }                  
                else
                    $(".box_comment_" + deleteId).show().html("Could not delete");
                return false;
			});
		}else
			return false;
	});
});		
</script>		  